package com.tangguo.vshop.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tangguo.vshop.domain.Order;
import com.tangguo.vshop.repository.OrderRepository;
import com.tangguo.vshop.security.JwtUser;

/**
 * 订单
 * @author doonly
 *
 */
@RestController 
@RequestMapping("/order")
public class OrderController {
	@Autowired
	private OrderRepository orderRepository;
	@RequestMapping("/search")
	public Page<Order> search(String keywords,Pageable pageable){
		JwtUser jwtUser = (JwtUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		if(keywords==null||"".equals(keywords)){
			return orderRepository.findByCreator(jwtUser.getId(),pageable);
		}
		return orderRepository.findByCodeAndCreator(keywords,jwtUser.getId(),pageable);

	}
}
